package ca.cbc.gis.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;

public class GISResponseBuilder<T> {
	private static Logger logger = LoggerFactory.getLogger(GISResponseBuilder.class);

	public Response build(T obj) {
		ResponseBuilder builder = null;
		try {
			GenericEntity<T> entity = new GenericEntity<T>(obj) {};
			builder = Response.ok(entity);
		} catch (Exception e) {
			logger.error("Exception when building response!", e);
			builder = Response.status(Status.SERVICE_UNAVAILABLE);
		}
		return builder.build();
	}
}
